/***************************************************************
*  Copyright (c) 2007 by GroupMe! Team (www.groupme.net)
*  All rights reserved
*
*  This file is part of the GroupMe! Project. You can utilize
*  software of the GroupMe! project under the terms of the 
*  GNU Lesser General Public License as published by the
*  Free Software Foundation in version 2.1.
* 
*  The GNU Lesser General Public License can be found at:
*  http://www.gnu.org/licenses/lgpl.html
*
*  This copyright notice MUST APPEAR in all copies of the file!
***************************************************************/
package net.groupme.utils.sql;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.sql.DataSource;

import net.groupme.export.rdf.TaggingContext;
import net.groupme.export.rdf.TaggingContext;
import net.groupme.model.dao.DATABASE_CONSTANTS;

import org.springframework.jdbc.object.MappingSqlQuery;

/**
 * 
 * This class provides...

 * @author Daniel Plappert
 * @version 0.1
 *
 */

public class GetTaggingContextQuery extends MappingSqlQuery {

    private DataSource datasource;

    /**
     * Constructor
     *
     * @param DataSource
     * @param String query
     */
    public GetTaggingContextQuery(DataSource ds, String query) {
        
        super(ds, query);
        this.datasource = ds;
        compile();
    }

    
    /**
     *
     *
     * @param ResultSet
     * @param int
     * @return List<TaggingContext>
     */
    protected Object mapRow(ResultSet rs, int rowNum) throws SQLException {
        List<TaggingContext> taggingContextCollection = new ArrayList<TaggingContext>();
        TaggingContext tempTaggingContext;
        
        while (!rs.isAfterLast()){
            tempTaggingContext = new TaggingContext();
            tempTaggingContext.setGroup(rs.getInt(DATABASE_CONSTANTS.USERTAGGROUPRESOURCE_GROUPID));
            tempTaggingContext.setResource(rs.getInt(DATABASE_CONSTANTS.USERTAGGROUPRESOURCE_RESOURCEID));
            tempTaggingContext.setUser(rs.getInt(DATABASE_CONSTANTS.USERTAGGROUPRESOURCE_USERID));
            tempTaggingContext.setImportance(rs.getInt(DATABASE_CONSTANTS.USERTAGGROUPRESOURCE_IMPORTANCE));
            tempTaggingContext.setCreationDate(rs.getDate(DATABASE_CONSTANTS.USERTAGGROUPRESOURCE_DATE));
            tempTaggingContext.setTag(rs.getInt(DATABASE_CONSTANTS.USERTAGGROUPRESOURCE_TAGID));
            taggingContextCollection.add(tempTaggingContext);
            rs.next();
        }
        
    	return taggingContextCollection; 
    }

}
